export default {
  name: 'ProductMaintenance',
  data() {
    return {
      // 搜索表单
      searchForm: {
        category: '',
        subCategory: '',
        name: ''
      },
      // 表格数据
      tableData: [],
      // 选中的行
      selectedRows: [],
      // 分页信息
      pagination: {
        currentPage: 1,
        pageSize: 10,
        total: 0
      },
      // 弹窗显示控制
      dialogVisible: false,
      dialogTitle: '新增产品',
      // 表单数据
      formData: {
        category: '',
        subCategory: '',
        name: '',
        price: 0
      },
      // 表单验证规则
      formRules: {
        category: [
          { required: true, message: '请选择类别', trigger: 'change' }
        ],
        subCategory: [
          { required: true, message: '请选择子类', trigger: 'change' }
        ],
        name: [
          { required: true, message: '请输入项目名称', trigger: 'blur' }
        ],
        price: [
          { required: true, message: '请输入单价', trigger: 'blur' }
        ]
      },
      // 类别选项
      categoryOptions: [
        { value: '服务费', label: '服务费' },
        { value: '寿衣', label: '寿衣' },
        { value: '灵堂', label: '灵堂' },
        { value: '小物件', label: '小物件' },
        { value: '寿盒', label: '寿盒' },
        { value: '鲜花', label: '鲜花' },
        { value: '烧纸碗', label: '烧纸碗' },
        { value: '安葬', label: '安葬' }
      ],
      // 子类选项（根据选择的类别动态变化）
      subCategoryOptions: []
    }
  },
  methods: {
    // 搜索
    handleSearch() {
      // 实现搜索逻辑
    },
    // 重置搜索
    resetSearch() {
      this.searchForm = {
        category: '',
        subCategory: '',
        name: ''
      }
      this.handleSearch()
    },
    // 新增
    handleAdd() {
      this.dialogTitle = '新增产品'
      this.formData = {
        category: '',
        subCategory: '',
        name: '',
        price: 0
      }
      this.dialogVisible = true
    },
    // 编辑
    handleEdit(row) {
      this.dialogTitle = '编辑产品'
      this.formData = { ...row }
      this.dialogVisible = true
    },
    // 删除
    handleDelete(row) {
      this.$confirm('确认删除该产品?', '提示', {
        type: 'warning'
      }).then(() => {
        // 实现删除逻辑
      })
    },
    // 批量删除
    handleBatchDelete() {
      if (this.selectedRows.length === 0) {
        this.$message.warning('请选择要删除的产品')
        return
      }
      this.$confirm(`确认删除选中的${this.selectedRows.length}个产品?`, '提示', {
        type: 'warning'
      }).then(() => {
        // 实现批量删除逻辑
      })
    },
    // 表单提交
    handleSubmit() {
      this.$refs.productForm.validate((valid) => {
        if (valid) {
          // 实现保存逻辑
          this.dialogVisible = false
        }
      })
    },
    // 选择变化
    handleSelectionChange(val) {
      this.selectedRows = val
    },
    // 页码变化
    handleCurrentChange(val) {
      this.pagination.currentPage = val
      this.handleSearch()
    },
    // 每页条数变化
    handleSizeChange(val) {
      this.pagination.pageSize = val
      this.handleSearch()
    }
  }
}